Omplus.base.define(Omplus.controllers.Controller, {
    omplusName:"contentController"
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"ContentTextsSearch",
    controller:"contentController",
    value:{
        "asset_name":{
            omplusType:"String"
        },
        "local_value":{
            omplusType:"String"
        },
        delta:{
            omplusType:"Number",
            value:5
        },
        start:{
            omplusType:"Number",
            value:0
        }
    }
});

Omplus.models.ContentTextsSearchModelProto = Omplus.base.extend(Omplus.models.Object, {
    omplusType:"ContentTextsSearchModelProto",
    value:{
        "asset_name":{
            omplusType:"String"
        },
        "local_value":{
            omplusType:"String"
        }
    }
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"ContentTextsSearchResults",
    controller:"contentController",
    value:{
        assets:{
            omplusType:"Array",
            omplusProto:"ContentTextsSearchModelProto"
        },
        total:{
            omplusType:"Number"
        }
    }
});

Omplus.base.define(Omplus.views.ManagementPanel, {
    omplusName:"contentTextsPanel",
    controller:"contentController",
    renderTo:"managements",
    models:{
        search:"ContentTextsSearch",
        searchResult:"ContentTextsSearchResults",
        searchResultList:"assets"
    },
    views:{
        search:[
            {
                model:"ContentTextsSearch.asset_name",
                labelModel:"Assets.list.asset_name_label.localValue",
                inputType:"TextInput"
            },
            {
                model:"ContentTextsSearch.local_value",
                labelModel:"Assets.list.local_value_label.localValue",
                inputType:"TextInput"
            },
            {
                // Per page
                inputType:"Select",
                model:"PerPages",
                showModel:"number",
                current:"forTransactionPlayers",
                controller:"languageController",
                labelModel:"Assets.list.label_per_page.localValue",
                perPage:true
            },
            {
                // Search button
                inputType:"Button",
                controller:"languageController",
                model:"Assets.list.label_search_button.localValue",
                cssClasses:["search-button"],
                labelWidth:"0%",
                inputWidth:"100%",
                searchButton:true
            },
            {
                // Add button
                omplusType:"Button",
                omplusName:"AddAssetButton",
                controller:"languageController",
                model:"Assets.list.label_add.localValue",
                click:function () {
                    Omplus.globals.getObject("AddNewAsset").show();
                }
            }
        ],
        searchResult:[
            {
                labelModel:"Assets.list.asset_name_label.localValue",
                width:"220px",
                omplusType:"Label",
                model:"asset_name"
            },
            {
                labelModel:"Assets.list.local_value_label.localValue",
                width:"350px",
                omplusType:"Label",
                model:"local_value"
            },
            {
                omplusType:"Button",
                model:"Assets.list.label_edit.localValue",
                width:"160px",
                controller:"languageController",
                click:function () {
                    var asset_name = $(this).closest(".tableRow").find("label:first").text();
                    var local_value = $(this).closest(".tableRow").children("div").find("div:nth-child(2)").find("label").text();
                    Omplus.globals.getObject("AssetEditModel.asset_name").setValue(asset_name);
                    Omplus.globals.getObject("AssetEditModel.local_value").setValue(local_value);
                    Omplus.globals.getObject("EditAsset").show();
                }
            },
            {
                omplusType:"Button",
                model:"Assets.list.label_delete.localValue",
                width:"160px",
                controller:"languageController",
                click:function () {
                    var asset = $(this).closest(".tableRow").find("label:first").text();
                    Omplus.globals.getObject("AssetEditModel.for_deletion").setValue(asset);
                    Omplus.globals.getObject("DeleteAsset").show();
                }
            }
        ]
    }
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"ContentAssetsModel",
    controller:"contentController",
    value:{
        "asset_name":{
            omplusType:"String"
        },
        "local_value":{
            omplusType:"String"
        }
    },
    actions:[
        {
            omplusType:"Get",
            omplusName:"addAsset",
            proxy:{
                omplusType:"AjaxProxy"
            },
            requestModel:"ContentAssetsModel",
            responseModel:"ContentTextsSearchResults"
        },
        {
            omplusType:"Get",
            omplusName:"deleteAsset",
            proxy:{
                omplusType:"AjaxProxy"
            },
            requestModel:"AssetEditModel",
            callback:function() {
                $("#contentTextsPanel_searchButton_input").click();
            }
        },
        {
            omplusType:"Get",
            omplusName:"editAsset",
            proxy:{
                omplusType:"AjaxProxy"
            },
            requestModel:"AssetEditModel",
            callback:function() {
                $("#contentTextsPanel_searchButton_input").click();
            }
        }
    ]
});

Omplus.base.define(Omplus.views.Dialog, {
    omplusName:"AddNewAsset",
    width:"500px",
    height:"160px",
    components:[
        {
            omplusType:"LabelInputPair",
            omplusName:"addAssetName",
            labelModel:"Assets.list.asset_name_label.localValue",
            model:"ContentAssetsModel.asset_name",
            controller:"contentController",
            labelController:"languageController",
            width: "90%"
        },
        {
            omplusType:"LabelInputPair",
            omplusName:"addLocalValue",
            model:"ContentAssetsModel.local_value",
            controller:"contentController",
            labelModel:"Assets.list.local_value_label.localValue",
            labelController:"languageController",
            inputType:"TextArea",
            width: "90%"
        }
    ],
    confirmClick:function () {
        Omplus.globals.getObject("ContentAssetsModel").getAction("addAsset").run();
        Omplus.globals.getObject("AddNewAsset").hide();
    }
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"AssetEditModel",
    controller:"contentController",
    value:{
        for_deletion:{
            omplusType:"String"
        },
        asset_name : {
            omplusType:"String"
        },
        local_value : {
            omplusType:"String"
        }
    }
});

Omplus.base.define(Omplus.views.Dialog, {
    omplusName:"DeleteAsset",
    width:"500px",
    height:"100px",
    components:[
        {
            omplusType:"Label",
            omplusName:"deleteAssetQuestion",
            model:"Assets.list.delete_asset_question_label.localValue",
            controller:"languageController",
            width:"100%"
        }
    ],
    confirmClick:function () {
        Omplus.globals.getObject("ContentAssetsModel").getAction("deleteAsset").run();
        Omplus.globals.getObject("DeleteAsset").hide();
    }
});

Omplus.base.define(Omplus.views.Dialog, {
    omplusName:"EditAsset",
    width:"500px",
    height:"180px",
    components:[
        {
            omplusType:"Label",
            omplusName:"editAssetQuestion",
            model:"Assets.list.edit_asset_question_label.localValue",
            controller:"languageController"
        },
        {
            omplusType:"LabelInputPair",
            omplusName:"editAssetName",
            model:"AssetEditModel.asset_name",
            controller:"contentController",
            labelModel:"Assets.list.asset_name_label.localValue",
            labelController:"languageController",
            inputType:"Label",
            labelWidth:"30%",
            inputWidth:"60%"
        },
        {
            omplusType:"LabelInputPair",
            omplusName:"editLocalValue",
            model:"AssetEditModel.local_value",
            controller:"contentController",
            labelModel:"Assets.list.local_value_label.localValue",
            labelController:"languageController",
            inputType:"TextArea",
            labelWidth:"30%",
            inputWidth:"60%"
        }
    ],
    confirmClick:function () {
        Omplus.globals.getObject("ContentAssetsModel").getAction("editAsset").run();
        Omplus.globals.getObject("EditAsset").hide();
    }
});
